package com.onLineCar.manages.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.onLineCar.manages.pojo.ImageTable;
import com.onLineCar.manages.mapper.ImageTableMapper;
import com.onLineCar.manages.service.ImageTableService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;

import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 图片表 服务实现类
 * </p>
 *
 * @author zhucaiyi
 * @since 2023-12-11
 */
@Service


@Slf4j

public class ImageTableServiceImpl extends ServiceImpl<ImageTableMapper, ImageTable> implements ImageTableService {

    @Override
    public List<ImageTable> queryImageTableByBusinessId(Integer businessId) {
        LambdaQueryWrapper<ImageTable> imageTableLambdaQueryWrapper = new LambdaQueryWrapper<>();
        imageTableLambdaQueryWrapper.eq(ImageTable::getBusinessId, businessId);
        return this.list(imageTableLambdaQueryWrapper);
    }

    @Override
    public void deleteImagesByBusinessId(Integer BusinessId) {

        LambdaQueryWrapper<ImageTable> imageTableLambdaQueryWrapper = new LambdaQueryWrapper<>();
        imageTableLambdaQueryWrapper.eq(ImageTable::getBusinessId, BusinessId);
        this.remove(imageTableLambdaQueryWrapper);

        if (this.queryImageTableByBusinessId(BusinessId).size() > NumberUtils.INTEGER_ZERO) {
            this.remove(new LambdaQueryWrapper<ImageTable>().eq(ImageTable::getBusinessId, BusinessId));
        }
        log.info("删除图片表失败，未找到该业务id对应的图片");

    }

    @Override
    public List<ImageTable> queryImageTableByBusinessIdsAndImageCode(List<Integer> vehiclelist, Integer imageType) {
        LambdaQueryWrapper<ImageTable> imageTableLambdaQueryWrapper = new LambdaQueryWrapper<>();
        imageTableLambdaQueryWrapper.in(ImageTable::getBusinessId, vehiclelist);
        imageTableLambdaQueryWrapper.eq(ImageTable::getImageCode, imageType);
        imageTableLambdaQueryWrapper.eq(ImageTable::getIsDeleted, NumberUtils.INTEGER_ZERO);
        List<ImageTable> imageTables = this.list(imageTableLambdaQueryWrapper);
        return imageTables;
    }
}
